package com.sh.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


/**
* @comments
* @author  zg
* @date 2018年4月6日
*/
public class PropertiesUtils {
	private Logger logger = LogManager.getLogger(this.getClass());
	
	private Properties CONF_PRO;

	public PropertiesUtils(String propertiesFile) {
		CONF_PRO = loadPro(propertiesFile);
	}
	
	private Properties loadPro(String file){
		Properties pro = new Properties();
		try {
			InputStream is = this.getClass().getResourceAsStream(file);
			pro.load(is);
		} catch (IOException e) {
			logger.error("",e);
		}
		return pro;
	}
	
	public String getString(String key){
		String val = CONF_PRO.getProperty(key);
		return val;
	}
	
	public int getInt(String key){
		String valStr = getString(key);
		int valInt = 0;
		try {
			valInt = Integer.valueOf(valStr);
		} catch (NumberFormatException e) {
			logger.error("", e);;
		}
		return valInt;
	}
	
	public long getLong(String key){
		String valStr = getString(key);
		long valLong = 0;
		try {
			valLong = Long.valueOf(valStr);
		} catch (NumberFormatException e) {
			logger.error("", e);;
		}
		return valLong;
	}
	
	
	/*public static void main(String[] args) {
		PropertiesUtils pro = new PropertiesUtils("/conf.properties");
		System.out.println(pro.getString("bind.checkFrequencyMsec"));
	}*/
}
